<?php
	session_start();
	header("Content-type: text/javascript");
	require_once('../../lib/class.fonctions.php');
	$browser = strtolower($_SERVER['HTTP_USER_AGENT']);
	define('DIR_TRAD', '../trad/');
	$browser = (strstr($browser, 'MSIE')) ? 'ie' : 'ff';
	$url_site = "http://" . $_SERVER["SERVER_NAME"] . dirname($_SERVER["SCRIPT_NAME"]) . "/";
	
	if (strstr($url_site, '//'))
	{
		$url_site = str_replace('//', '/', $url_site);
		$url_site = str_replace(':/', '://', $url_site);
	}
	
	$url_site = str_replace('/js', '', $url_site);
?>	
	function rw(page, suite)
	{
		var url = 'index.php?pagerw='+encode64(suite)+'&suiterw=' + encode64(suite);
		var res = Get_HTML(url, 'get');
		var reg = new RegExp('(APPLNG)', 'gi');
		res.replace(reg, applng);
		return res;
	}
	
	function clearcache()
	{
		var url = 'index.php?clearcache=1';
		var res = Get_HTML(url, 'get');
		if (res == 'OK')
			alert('Cache empty');
		return false;
	}
	
	function trad(chaine)
	{
		var url = 'index.php?traduction_bo=1&lng='+applng+'&chaine='+chaine;
		var res = Get_HTML(url, 'get');
		if (res.length > 0)
			return res;
		return chaine;
	}
	
	function aff_filtre()
	{
		$('#filtre').show(500);
		$('#addpng').show(500);
		$('#okpng').show(500);
		document.getElementById('spanfiltre').setAttribute('onclick', 'cache_filtre()');
		document.getElementById('titre_filtre').innerHTML = trad('Masquer le filtre');
		addfiltre();
	}
	
	function cache_filtre()
	{
		$('#filtre').hide(500);
		$('#addpng').hide(500);
		$('#okpng').hide(500);
		document.getElementById('spanfiltre').setAttribute('onclick', 'aff_filtre()');
		document.getElementById('titre_filtre').innerHTML = trad('Ajouter un filtre');
	}
	
	function sql(requete)
	{
		var url = 'index.php?ajaxsql=1&r=' + encode64(requete);
		var methode = 'GET';
		var res = Get_HTML(url, methode);
		return res;
	}
	
	function in_array(str, tab)
	{
		for (var i = 0 ; i < tab.length ; i++)
		{
			var seg = tab[i];
			if (seg == str)
				return true;
		}
		return false;
	}
	
	function go(url)
	{
		document.location.href = url;
	}
	
	function changelng(lng)
	{
		var old = $("#oldlng").val();
		if (old != lng)
		{
			document.getElementById('setlng').value = lng;
			document.getElementById('redir').value = document.URL;
			$("#chnlng").submit();
		}
	}
	
	function Get_HTML(url, methode)
	{
		methode = methode.toUpperCase();
		if (window.XMLHttpRequest)
	        var objXHR = new XMLHttpRequest();
		else
		{
	        if (window.ActiveXObject)
	            var objXHR = new ActiveXObject("Microsoft.XMLHTTP");
			else
	            return false;
	    }

	    objXHR.open(methode, url, false);
		if (methode == 'POST')
			objXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    objXHR.send(null);

	    if (objXHR.readyState == 4)
	        return objXHR.responseText;
	    else
	        return false;
	}
	
	function contient(chaine, verif)
	{
		var compte = 0; 
	 
		for (var i = 0; i < chaine.length; i++) 
		{
			if (verif.indexOf(chaine.charAt(i)) > -1) 
				compte++; 
		} 
		return compte; 
	}
	
	
	var keyStr = "ABCDEFGHIJKLMNOP" + "QRSTUVWXYZabcdef" + "ghijklmnopqrstuv" + "wxyz0123456789+/" + "=";

	function encode64(input) 
	{
		input = escape(input);
		var output = "";
		var chr1, chr2, chr3 = "";
		var enc1, enc2, enc3, enc4 = "";
		var i = 0;

		do 
		{
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2))
				enc3 = enc4 = 64;
			else if (isNaN(chr3))
				enc4 = 64;

			output = output +
			keyStr.charAt(enc1) +
			keyStr.charAt(enc2) +
			keyStr.charAt(enc3) +
			keyStr.charAt(enc4);
			chr1 = chr2 = chr3 = "";
			enc1 = enc2 = enc3 = enc4 = "";
		} 
		while (i < input.length);

		return output;
	}
	
	function pause(sec) 
	{
		var maintenant = new Date();
		var millisecondes = sec * 1000;
		var sortie = maintenant.getTime() + millisecondes;
		
		while (true) 
		{
			maintenant = new Date();
			if (maintenant.getTime() > sortie)
				return;
		}
	}
	
	function getPageScroll()
	{
		var yScroll;

		if (self.pageYOffset) 
			yScroll = self.pageYOffset;
		else if (document.documentElement && document.documentElement.scrollTop)
			yScroll = document.documentElement.scrollTop;
		else if (document.body)
			yScroll = document.body.scrollTop;

		arrayPageScroll = new Array('', yScroll) 
		return arrayPageScroll;
	}

	
	function getPageSize()
	{
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) 
		{	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} 
		else if (document.body.scrollHeight > document.body.offsetHeight)
		{ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} 
		else 
		{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) 
		{	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} 
		else if (document.documentElement && document.documentElement.clientHeight) 
		{ // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} 
		else if (document.body) 
		{ // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight)
			pageHeight = windowHeight;
		else
			pageHeight = yScroll;

		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth)
			pageWidth = windowWidth;
		else
			pageWidth = xScroll;


		arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight) 
		return arrayPageSize;
	}